package org.msn.util;

import io.netty.channel.ChannelHandlerContext;
import org.msn.model.pd.RestResultProto;
import org.msn.model.rest.RestCode;

public class RequestUtil {
    public static void sendRequest(ChannelHandlerContext ctx, RestResultProto.RestResult restResult) {
        ctx.writeAndFlush(JsonUtil.toJson(restResult));
    }

    public static RestResultProto.RestResult generateRestResultProto(RestCode restCode, Object data) {
        RestResultProto.RestResult.Builder builder = RestResultProto.RestResult.newBuilder();
        builder.setCode(restCode.getCode());
        builder.setMsg(restCode.getMsg());
        if (data != null) {
            builder.setData(JsonUtil.toJson(data));
        }
        return builder.build();
    }
}